jQuery(document).ready(function () {
    selectList();
    $("#resetBtn").on("click",function () {
        $("#customerName").val("");
        $("#productName").val("");
        $("#orderId").val("");
        $("#contact").val("");
        $("#telephone").val("");
        $("#address").val("");
        $("#state").val("");
        $("#startTime").val("");
        $("#endTime").val("");
    });
});
function queryParams(params) {
    return getQueryParams(params, "searchForm");
}
function selectList(){
    $('#orderTable').bootstrapTable("destroy");
    $('#orderTable').bootstrapTable({
        method: "post",
        url: rootPath+"/orderManage/ajax/getOrderList",
        showExport : true,
        exportTypes: ['excel'],//['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
        Icons:'glyphicon-export',
        exportOptions:{
            ignoreColumn: [0],  //忽略某一列的索引
            fileName: '订单列表',  //文件名称设置
            worksheetName: 'sheet1',  //表格工作区名称
            tableName: '订单列表'
        },
        exportDataType : 'all'
    });
}
function updOrderInfo() {
    var selections = $('#orderTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if (selections[0].state != 1){
        layer.msg('所选订单状态不允许进行修改！', function () {
        });
        return;
    }
    layer.open({
        type: 2,
        title: "修改订单信息",
        shadeClose: false,
        shade: 0.8,
        area: ['70%', '70%'],
        content: rootPath + "/orderManage/toPage/orderUpdView?decorator=decorator_blank&orderId="+selections[0].order_id,
        maxmin: true
    });
}
function productFormatter(value,row,index) {
    return '<a onclick="javascript:commonJs.alertMsg('+"\'"+'产品名称：《'+row.product_name+'》，作者：'+row.author+'，出版社：'+row.press+'，价格：'+row.price+'元'+"\'"+');">'+value+'</a>';
}
function orderEnd() {
    var selections = $('#orderTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if (selections[0].state != 1){
        layer.msg('所选订单状态不允许进行此操作！', function () {
        });
        return;
    }
    var orderId = selections[0].order_id;
    var productId = selections[0].product_id;
    layer.open({
        content: '确定此订单已送达？',
        btn: ['确定', "取消"],
        shade: false,
        offset: '200px',
        yes: function (index, layero) {
            $.ajax({
                type: "POST",
                url: rootPath + "/orderManage/ajax/updOrderState",
                data:{orderId:orderId,productId:productId,state:2},
                dataType: "json",
                success : function(data) {
                    $("#orderTable").bootstrapTable('refresh');//刷新表格
                    if(data.code == '0000') {
                        layer.msg(data.msg, {icon: 1});
                    }else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error:function(){
                    layer.msg("操作出错！",{icon: 2});
                }
            });
        },
        cancel: function (index) {
        }
    });
}
function delOrder() {
    var selections = $('#orderTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if (selections[0].state != 1){
        layer.msg('所选订单状态不允许进行此操作！', function () {
        });
        return;
    }
    var orderId = selections[0].order_id;
    var productId = selections[0].product_id;
    layer.open({
        content: '确定将此订单取消？',
        btn: ['确定', "取消"],
        shade: false,
        offset: '200px',
        yes: function (index, layero) {
            $.ajax({
                type: "POST",
                url: rootPath + "/orderManage/ajax/updOrderState",
                data:{orderId:orderId,productId:productId,state:0},
                dataType: "json",
                success : function(data) {
                    $("#orderTable").bootstrapTable('refresh');//刷新表格
                    if(data.code == '0000') {
                        layer.msg(data.msg, {icon: 1});
                    }else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error:function(){
                    layer.msg("操作出错！",{icon: 2});
                }
            });
        },
        cancel: function (index) {
        }
    });
}